﻿using DataProcess.Core.Model;
using System;
using System.Collections.Generic;

namespace DataProcess4Net48.Views
{
    public partial class LogForm : DevExpress.XtraEditors.XtraForm
    {
        public LogForm(List<LogItem> logs)
        {
            InitializeComponent();
            InitLogs(logs);
        }

        private void LogForm_Load(object sender, EventArgs e)
        {
        }

        private string GetColor(string level)
        {
            if (level == log4net.Core.Level.Error.Name)
            {
                return "#F44336";
            }
            else if (level == log4net.Core.Level.Info.Name)
            {
                return "#03A9F4";
            }
            else if (level == log4net.Core.Level.Warn.Name)
            {
                return "#F9A825";
            }
            return "Black";
        }

        public void InitLogs(List<LogItem> logs)
        {
            LogListControl.Items.Clear();
            foreach (var log in logs)
            {
                string html = $"<size=14><color={GetColor(log.Level)}>{log.Time:yyyy-MM-dd HH:mm:ss}    {log.Message}</color></size>";
                LogListControl.Items.Add(html);
            }
        }
    }
}